home *** CD-ROM | disk | FTP | other *** search
/ Aminet 43 / Aminet 43 (2001)(GTI - Schatztruhe)[!][Jun 2001].iso / Aminet / dev / moni / SystemViewer.lha / Source / SysDevs.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-25  |  24.9 KB  |  976 lines

  1. /****h* SystemDevices/SysDevs.c [1.0] ********************************
  2. *
  3. * NAME
  4. *    SysDevs.c
  5. *
  6. * DESCRIPTION
  7. *    Display a list of all Devices currently known to the OS.
  8. *
  9. * FUNCTIONAL INTERFACE:
  10. *
  11. *   FUNCTIONS FROM SysCommon.c:
  12. *
  13. *     PUBLIC int  SetupSystemList( (*OpenWindowFunc)( void ) );
  14. *
  15. *     PUBLIC void ShutdownSystemList( void );
  16. *
  17. *   FUNCTIONS FROM Priority.c:
  18. *
  19. *     PUBLIC int ChangePriorityHandler( char *name, int ObjType, 
  20. *                                       int frompri
  21. *                                     );
  22. **********************************************************************
  23. *
  24. */
  25.  
  26. #include <string.h>
  27.  
  28. #include <exec/execbase.h>
  29. #include <exec/types.h>
  30. #include <exec/devices.h>
  31. #include <exec/libraries.h>
  32.  
  33. #include <intuition/intuition.h>
  34. #include <intuition/classes.h>
  35. #include <intuition/classusr.h>
  36. #include <intuition/gadgetclass.h>
  37.  
  38. #include <libraries/gadtools.h>
  39.  
  40. #include <graphics/displayinfo.h>
  41. #include <graphics/gfxbase.h>
  42.  
  43. #include <clib/exec_protos.h>
  44. #include <clib/intuition_protos.h>
  45. #include <clib/gadtools_protos.h>
  46. #include <clib/graphics_protos.h>
  47. #include <clib/diskfont_protos.h>
  48.  
  49. #include "CPGM:GlobalObjects/CommonFuncs.h"
  50.  
  51. #include "SysLists.h"
  52.  
  53. #ifndef  StrBfPtr
  54. # define StrBfPtr( g ) (((struct StringInfo *)g->SpecialInfo)->Buffer)
  55. #endif
  56.  
  57. #define DLV       0
  58. #define Update    1
  59. #define Cancel    2
  60. #define RemoveBt  3
  61. #define Priority  4
  62. #define Close     5
  63. #define Flush     6
  64.  
  65. #define DEVICELISTGADGET DLRGadgets[ DLV ]
  66.  
  67. #define DLR_CNT   7
  68.  
  69. PUBLIC struct List *DevListPtr = NULL;
  70.  
  71. PRIVATE char ver[] = "$VER: SysDevices 1.0 (12/20/1999) by J.T. Steichen";
  72.  
  73. PRIVATE char tstr[] = "Address  Type      Pri  Open Version    Neg   Pos Name";
  74. PRIVATE char fmt[]  = "%08LX %-8.8s %4d %5d %-8.8s %5d %5d %-29.29s";
  75.  
  76.  
  77. PRIVATE struct Library *CurrentDLR = NULL;
  78.  
  79.  
  80. PRIVATE struct Window       *DLRWnd   = NULL;
  81. PRIVATE struct Gadget       *DLRGList = NULL;
  82. PRIVATE struct IntuiMessage  DLRMsg;
  83. PRIVATE struct Gadget       *DLRGadgets[ DLR_CNT ];
  84. PRIVATE struct TextFont     *DLRFont  = NULL;
  85.  
  86. PRIVATE UWORD  DLRLeft   = 0;
  87. PRIVATE UWORD  DLRTop    = 16;
  88. PRIVATE UWORD  DLRWidth  = 635;
  89. PRIVATE UWORD  DLRHeight = 230;
  90. PRIVATE UBYTE *DLRWdt    = "System Device/Library/Resource Info:";
  91.  
  92. // -------------------------------------------------------------------
  93.  
  94. #define MAXDEVS    150
  95. #define NODELENGTH 80
  96.  
  97. PRIVATE struct MinList DLRList;
  98. PRIVATE struct Node    DLRNode;
  99. PRIVATE struct Node    DLRNodes[ MAXDEVS ] = { NULL, };
  100. PRIVATE UBYTE          NodeStrs[ MAXDEVS * NODELENGTH ] = "";
  101.  
  102. // -------------------------------------------------------------------
  103.  
  104. UWORD DLRGTypes[] = {
  105.  
  106.    LISTVIEW_KIND,   BUTTON_KIND,   BUTTON_KIND,
  107.    BUTTON_KIND,     BUTTON_KIND,   BUTTON_KIND, 
  108.    BUTTON_KIND
  109. };
  110.  
  111. PRIVATE int DLVClicked(      int whichitem );
  112. PRIVATE int UpdateClicked(   int dummy     );
  113. PRIVATE int CancelClicked(   int dummy     );
  114. PRIVATE int RemoveClicked(   int dummy     );
  115. PRIVATE int PriorityClicked( int dummy     );
  116. PRIVATE int CloseClicked(    int dummy     );
  117. PRIVATE int FlushClicked(    int dummy     );
  118.  
  119. PRIVATE struct NewGadget DLRNGad[] = {
  120.  
  121.      2,   3, 627, 200,                NULL,    NULL, DLV,      0, 
  122.    NULL, (APTR) DLVClicked,
  123.    
  124.      4, 205,  72,  17, (UBYTE *) "_Update",    NULL, Update,
  125.    PLACETEXT_IN, NULL, (APTR) UpdateClicked,
  126.  
  127.    554, 205,  72,  17, (UBYTE *) "_Cancel",    NULL, Cancel,
  128.    PLACETEXT_IN, NULL, (APTR) CancelClicked,
  129.  
  130.     89, 205,  72,  17, (UBYTE *) "Remove",     NULL, RemoveBt,
  131.    PLACETEXT_IN, NULL, (APTR) RemoveClicked,
  132.  
  133.    172, 205,  72,  17, (UBYTE *) "Priority",   NULL, Priority, 
  134.    PLACETEXT_IN, NULL, (APTR) PriorityClicked,
  135.    
  136.    255, 205,  72,  17, (UBYTE *) "Close",      NULL, Close,
  137.    PLACETEXT_IN, NULL, (APTR) CloseClicked,
  138.  
  139.    338, 205,  82,  17, (UBYTE *) "_Flush Sys", NULL, Flush,
  140.    PLACETEXT_IN, NULL, (APTR) FlushClicked
  141. };
  142.  
  143. PRIVATE ULONG DLRGTags[] = {
  144.  
  145.    GTLV_ShowSelected, NULL, LAYOUTA_Spacing, 2, TAG_DONE,
  146.  
  147.    GT_Underscore, '_', TAG_DONE,
  148.    GT_Underscore, '_', TAG_DONE,
  149.    GA_Disabled, TRUE,  TAG_DONE,
  150.    GA_Disabled, TRUE,  TAG_DONE,
  151.    GA_Disabled, TRUE,  TAG_DONE,
  152.    GA_Disabled, TRUE,  GT_Underscore, '_', TAG_DONE
  153. };
  154.  
  155. // -------------------------------------------------------------------
  156.  
  157. PRIVATE int InitializeDeviceList( void )
  158. {
  159.    IMPORT struct ExecBase *SysBase;
  160.  
  161.    struct Node   *ptr  = NULL;
  162.    struct Device *d    = NULL;
  163.    char v[20],   *vers = &v[0];
  164.    char t[10],   *type = &t[0];
  165.    char          *nm   = NULL;
  166.    int            i    = 0, version, rev;
  167.  
  168.    HideListFromView( DEVICELISTGADGET, DLRWnd );
  169.  
  170.    Forbid();
  171.  
  172.      DevListPtr = &SysBase->DeviceList;
  173.      ptr        = DevListPtr->lh_Head;
  174.      d          = (struct Device  *) ptr;
  175.      CurrentDLR = &(d->dd_Library);
  176.      version    = CurrentDLR->lib_Version;
  177.      rev        = CurrentDLR->lib_Revision;
  178.  
  179.      while (i < MAXDEVS && CurrentDLR != NULL)
  180.         {
  181.         nm = CurrentDLR->lib_Node.ln_Name; //lib_IdString;
  182.  
  183.         if (strlen( nm ) < 1)
  184.            goto SkipBlankDeviceName;
  185.  
  186.         if (CurrentDLR->lib_Node.ln_Type == NT_DEVICE)
  187.            strcpy( type, "device" );
  188.         else
  189.            strcpy( type, "????????" );
  190.            
  191.         sprintf( vers, "%4d.%-4d", version, rev );
  192.  
  193.         // "Address  Type    Pri  Open Version  Neg  Pos  Name"        
  194.         sprintf( &NodeStrs[ i++ * NODELENGTH ],
  195.                  &fmt[0],
  196.                  CurrentDLR, 
  197.                  type,
  198.                  CurrentDLR->lib_Node.ln_Pri,
  199.                  CurrentDLR->lib_OpenCnt,
  200.                  vers,
  201.                  CurrentDLR->lib_NegSize,
  202.                  CurrentDLR->lib_PosSize,
  203.                  (nm == NULL ? "** NO NAME **" : nm)
  204.                );
  205.  
  206. SkipBlankDeviceName:
  207.          
  208.         CurrentDLR = ((struct Library *) 
  209.                        CurrentDLR)->lib_Node.ln_Succ;
  210.  
  211.         if (CurrentDLR == NULL)
  212.            break;
  213.  
  214.         version = CurrentDLR->lib_Version;
  215.         rev     = CurrentDLR->lib_Revision;
  216.         } 
  217.  
  218.    Permit();
  219.  
  220.    Forbid();   
  221.  
  222.      if (i < MAXDEVS)
  223.         {
  224.         DevListPtr = &SysBase->ResourceList;
  225.         CurrentDLR = (struct Library *) DevListPtr->lh_Head;
  226.         version    = CurrentDLR->lib_Version;
  227.         rev        = CurrentDLR->lib_Revision;
  228.  
  229.         while (i < MAXDEVS && CurrentDLR != NULL)
  230.            {
  231.            nm = CurrentDLR->lib_Node.ln_Name; // lib_IdString;
  232.  
  233.            if (strlen( nm ) < 1)
  234.               goto SkipBlankResourceName;
  235.  
  236.            if (CurrentDLR->lib_Node.ln_Type == NT_RESOURCE)
  237.               strcpy( type, "resource" );
  238.            else
  239.               strcpy( type, "????????" );
  240.  
  241.            sprintf( vers, "%4d.%-4d", version, rev );
  242.  
  243.            // "Address  Type    Pri  Open Version  Neg  Pos  Name"        
  244.            sprintf( &NodeStrs[ i++ * NODELENGTH ], 
  245.                     &fmt[0],
  246.                     CurrentDLR, 
  247.                     type,
  248.                     CurrentDLR->lib_Node.ln_Pri,
  249.                     CurrentDLR->lib_OpenCnt,
  250.                     vers,
  251.                     CurrentDLR->lib_NegSize,
  252.                     CurrentDLR->lib_PosSize,
  253.                     (nm == NULL ? "** NO NAME **" : nm)
  254.                   );
  255.  
  256. SkipBlankResourceName:
  257.          
  258.            CurrentDLR = ((struct Library *) 
  259.                           CurrentDLR)->lib_Node.ln_Succ;
  260.       
  261.            if (CurrentDLR == NULL)
  262.               break;
  263.  
  264.            version = CurrentDLR->lib_Version;
  265.            rev     = CurrentDLR->lib_Revision;
  266.            } 
  267.         }   
  268.  
  269.    Permit();
  270.  
  271.    Forbid();
  272.  
  273.      if (i < MAXDEVS)
  274.         {
  275.         DevListPtr = &SysBase->LibList;
  276.         CurrentDLR = (struct Library *) DevListPtr->lh_Head;
  277.         version    = CurrentDLR->lib_Version;
  278.         rev        = CurrentDLR->lib_Revision;
  279.         
  280.         while (i < MAXDEVS && CurrentDLR != NULL)
  281.            {
  282.            nm = CurrentDLR->lib_Node.ln_Name;
  283.  
  284.            if (strlen( nm ) < 1)
  285.               goto SkipBlankLibName;
  286.               
  287.            if (CurrentDLR->lib_Node.ln_Type == NT_LIBRARY)
  288.               strcpy( type, "library" );
  289.            else
  290.               strcpy( type, "????????" );
  291.  
  292.            sprintf( vers, "%4d.%-4d", version, rev );
  293.  
  294.            // "Address  Type    Pri  Open Version  Neg  Pos  Name"        
  295.            sprintf( &NodeStrs[ i++ * NODELENGTH ], 
  296.                     &fmt[0],
  297.                     CurrentDLR, 
  298.                     type,
  299.                     CurrentDLR->lib_Node.ln_Pri,
  300.                     CurrentDLR->lib_OpenCnt,
  301.                     vers,
  302.                     CurrentDLR->lib_NegSize,
  303.                     CurrentDLR->lib_PosSize,
  304.                     (nm == NULL ? "** NO NAME **" : nm)
  305.                   );
  306.  
  307. SkipBlankLibName:
  308.          
  309.            CurrentDLR = ((struct Library *) 
  310.                           CurrentDLR)->lib_Node.ln_Succ;
  311.       
  312.            if (CurrentDLR == NULL)
  313.               break;
  314.  
  315.            version = CurrentDLR->lib_Version;
  316.            rev     = CurrentDLR->lib_Revision;
  317.            }
  318.         }
  319.  
  320.      // Reset CurrentDLR to the Head of the list.
  321.      DevListPtr = &SysBase->DeviceList;
  322.      CurrentDLR = (struct Library *) DevListPtr->lh_Head;
  323.  
  324.    Permit();
  325.  
  326.    GT_SetGadgetAttrs( DEVICELISTGADGET, DLRWnd, NULL,
  327.                       GTLV_Labels,       &DLRList,
  328.                       GTLV_Selected,     0, 
  329.                       GTLV_MaxPen,       255,
  330.                       GTLV_ItemHeight,   12,
  331.                       TAG_END
  332.                     );
  333.  
  334.    DisplayTitle( DLRWnd, DLRWdt );
  335.  
  336.    return( i );
  337. }
  338.  
  339. // -----------------------------------------------------------------
  340.  
  341. PRIVATE void CloseDLRWindow( void )
  342. {
  343.    if (DLRWnd != NULL)
  344.       {
  345.       CloseWindow( DLRWnd );
  346.       DLRWnd = NULL;
  347.       }
  348.  
  349.    if (DLRGList != NULL)
  350.       {
  351.       FreeGadgets( DLRGList );
  352.       DLRGList = NULL;
  353.       }
  354.  
  355.    if (DLRFont != NULL)
  356.       {
  357.       CloseFont( DLRFont );
  358.       DLRFont = NULL;
  359.       }
  360.  
  361.    return;
  362. }
  363.  
  364. // -----------------------------------------------------------------
  365.  
  366. PRIVATE char wt[80] = { 0, }, *modtitle = &wt[0];
  367.  
  368.  
  369. PRIVATE int DLVClicked( int whichitem )
  370. {
  371.    ULONG addr = 0L;
  372.  
  373.    if (whichitem == 0)
  374.       {
  375.       // Disable buttons because user selected the title item:
  376.  
  377.       GT_SetGadgetAttrs( DLRGadgets[ RemoveBt ], DLRWnd, NULL,
  378.                          GA_Disabled, TRUE, TAG_DONE 
  379.                        );
  380.  
  381.       GT_SetGadgetAttrs( DLRGadgets[ Priority ], DLRWnd, NULL,
  382.                          GA_Disabled, TRUE, TAG_DONE 
  383.                        );
  384.    
  385.       GT_SetGadgetAttrs( DLRGadgets[ Close ], DLRWnd, NULL,
  386.                          GA_Disabled, TRUE, TAG_DONE 
  387.                        );
  388.    
  389.       GT_SetGadgetAttrs( DLRGadgets[ Flush ], DLRWnd, NULL,
  390.                          GA_Disabled, TRUE, TAG_DONE 
  391.                        );
  392.    
  393.       DisplayTitle( DLRWnd, DLRWdt );
  394.       
  395.       CurrentDLR = NULL;
  396.  
  397.       return( (int) TRUE );
  398.       }
  399.  
  400.    // Now get address from the item:
  401.    
  402.    (void) stch_l( DLRNodes[ whichitem ].ln_Name, (long *) &addr );
  403.  
  404.    CurrentDLR = (struct Library *) addr;
  405.     
  406.    if (addr != NULL)
  407.       {
  408.       sprintf( modtitle, "%-53.53s  You Selected:  %08LX", DLRWdt, addr );
  409.  
  410.       DisplayTitle( DLRWnd, modtitle );
  411.       }
  412.  
  413.    // Enable buttons because user made a valid selection from the ListView:
  414.  
  415.    GT_SetGadgetAttrs( DLRGadgets[ RemoveBt ], DLRWnd, NULL,
  416.                       GA_Disabled, FALSE, TAG_DONE 
  417.                     );
  418.  
  419.    GT_SetGadgetAttrs( DLRGadgets[ Priority ], DLRWnd, NULL,
  420.                       GA_Disabled, FALSE, TAG_DONE 
  421.                     );
  422.    
  423.    GT_SetGadgetAttrs( DLRGadgets[ Close ], DLRWnd, NULL,
  424.                       GA_Disabled, FALSE, TAG_DONE 
  425.                     );
  426.  
  427.    GT_SetGadgetAttrs( DLRGadgets[ Flush ], DLRWnd, NULL,
  428.                       GA_Disabled, FALSE, TAG_DONE 
  429.                     );
  430.    
  431.    return( (int) TRUE );
  432. }
  433.  
  434. // -----------------------------------------------------------------
  435.  
  436. PRIVATE int UpdateClicked( int dummy )
  437. {
  438.    int i;
  439.  
  440.    DisplayTitle( DLRWnd, "Updating list..." );
  441.    
  442.    for (i = 1; i <= MAXDEVS; i++)
  443.        NodeStrs[ i * NODELENGTH ] = '\0'; // Kill old ListView strings.
  444.  
  445.    if (InitializeDeviceList() <= 0)
  446.       {
  447.       // No Devices/Libraries/Resources known to SysBase!!
  448.       UserInfo( "No Device/Libraries/Resources found!", "OS ERROR??" );
  449.       }  
  450.  
  451.    GT_RefreshWindow( DLRWnd, NULL );
  452.  
  453.    DisplayTitle( DLRWnd, DLRWdt );
  454.  
  455.    return( (int) TRUE );
  456. }
  457.  
  458. // -----------------------------------------------------------------
  459.  
  460. PRIVATE int DLRCloseWindow( void )
  461. {
  462.    CloseDLRWindow();
  463.    return( (int) FALSE );
  464. }
  465.  
  466. // -----------------------------------------------------------------
  467.  
  468. PRIVATE int CancelClicked( int dummy )
  469. {
  470.    return( DLRCloseWindow() );
  471. }
  472.  
  473. // -----------------------------------------------------------------
  474.  
  475. // Flush Unused Libraries, Resources, etc., out of Memory:
  476.  
  477. PRIVATE int FlushClicked( int dummy )
  478. {
  479.    char command[32];
  480.  
  481.    strcpy( &command[0], "AVAIL FLUSH >NIL:" );
  482.    
  483.    if (System( &command[0], TAG_DONE ) < 0)
  484.       {
  485.       sprintf( ErrMsg, 
  486.                "%s couldn't be run by the System,\ncheck your path!",
  487.                &command[0]
  488.              );
  489.  
  490.       UserInfo( ErrMsg, "Invalid command path?" );
  491.  
  492.       return( (int) TRUE );
  493.       }
  494.  
  495.    (void) UpdateClicked( 0 ); // Re-make the ListView contents.
  496.  
  497.    return( (int) TRUE );
  498. }
  499.  
  500. // -----------------------------------------------------------------
  501.  
  502. PRIVATE int CloseClicked( int dummy )
  503. {
  504.    char *name = CurrentDLR->lib_Node.ln_Name;
  505.    int   type = CurrentDLR->lib_Node.ln_Type;
  506.    BOOL  ans  = 0;
  507.    
  508.    sprintf( ErrMsg, "Close will change the Open Count\n"
  509.                     "for %s, are you sure about this?",
  510.                     name
  511.           );
  512.    
  513.    ans = SanityCheck( ErrMsg );
  514.    
  515.    if (ans == FALSE)
  516.       return( TRUE ); // User came to her senses!
  517.          
  518.    switch (type)
  519.       {
  520.       case NT_LIBRARY:
  521.          if (CurrentDLR->lib_OpenCnt > 0)
  522.             CloseLibrary( CurrentDLR );
  523.          else
  524.             {
  525.             Forbid();
  526.                RemLibrary( CurrentDLR );
  527.             Permit();
  528.             }
  529.  
  530.          break;
  531.  
  532.       case NT_DEVICE:
  533.          UserInfo( "NOT Implemented for devices!", "User Information:" );
  534. /*
  535.          if (CurrentDLR->lib_OpenCnt > 0)
  536.             CloseDevice( (struct Device *) CurrentDLR );
  537.          else
  538.             {
  539.             Forbid();
  540.                RemDevice( (struct Device *) CurrentDLR );
  541.             Permit();
  542.             }         
  543. */       
  544.          break;
  545.  
  546.       case NT_RESOURCE:
  547.  
  548.          Forbid();
  549.             Remove( &(CurrentDLR->lib_Node) );
  550.          Permit();
  551.  
  552.          (void) FlushClicked( 0 );
  553.  
  554.          break;
  555. /*
  556.       case NT_DEVICE:
  557.          {
  558.          struct MsgPort        *dmport = NULL;
  559.          struct DosPacket      *reply  = NULL;
  560.          struct DevProc        *dp     = NULL;
  561.  
  562.          struct Message         msg    = { 0, };
  563.          struct StandardPacket  spack  = { 0, };
  564.          struct MsgPort         dport  = { 0, };
  565.          struct MsgPort         drport = { 0, };
  566.  
  567.          dp     = GetDeviceProc( name, dp );
  568.          dmport = dp->dvp_DevNode->dol_Task;   // Task MsgPort!
  569.          
  570.          or: 
  571.  
  572.          dmport = DeviceProc( (STRPTR) name ); // Task MsgPort!
  573.  
  574.          msg.mn_Node.ln_Name     = name;
  575.          msg.mn_ReplyPort        = &drport;
  576.  
  577.          spack.sp_Msg            = msg;
  578.  
  579.          spack.sp_Pkt.dp_Port    = &dport;
  580.          spack.sp_Pkt.dp_Status  = 0;
  581.          spack.sp_Pkt.dp_Status2 = 0;
  582.          spack.sp_Pkt.dp_Action  = ACTION_FLUSH;
  583.          
  584.          SendPkt( &spack.sp_Pkt, (dp->dvp_Port or dmport), &drport );
  585.          reply = WaitPkt();
  586.  
  587.          if (spack.sp_Pkt.dp_Status != DOSTRUE)
  588.             {
  589.             }
  590.          // error checking????
  591.  
  592.          msg.mn_Node.ln_Name     = name;
  593.          msg.mn_ReplyPort        = &drport;
  594.  
  595.          spack.sp_Msg            = msg;
  596.  
  597.          spack.sp_Pkt.dp_Port    = &dport;
  598.          spack.sp_Pkt.dp_Status  = 0;
  599.          spack.sp_Pkt.dp_Status2 = 0;
  600.          spack.sp_Pkt.dp_Action  = ACTION_DIE;
  601.  
  602.          SendPkt( &spack.sp_Pkt, (dp->dvp_Port or dmport), &drport );
  603.          reply = WaitPkt();
  604.  
  605.          if (spack.sp_Pkt.dp_Status != DOSTRUE)
  606.             {
  607.             }
  608.  
  609.          // Error checking???
  610.  
  611.          FreeDeviceProc( dp );
  612.          }
  613.          break;
  614. */
  615.       }
  616.  
  617.    (void) FlushClicked(  0 ); // Remove from system memory.
  618.    (void) UpdateClicked( 0 ); // Update the ListViewer.
  619.  
  620.    return( (int) TRUE );
  621. }
  622.  
  623. // -----------------------------------------------------------------
  624.  
  625. PRIVATE void RemoveTheDevice( struct Library *dev )
  626. {
  627. //   char *name = CurrentDLR->lib_Node.ln_Name;
  628.    int type = dev->lib_Node.ln_Type;
  629.  
  630.    switch (type)
  631.       {
  632.       case NT_LIBRARY:
  633.          while (dev->lib_OpenCnt > 0)
  634.             CloseLibrary( dev );
  635.          
  636.          Forbid();
  637.             RemLibrary( dev );
  638.          Permit();
  639.  
  640.          break;
  641.           
  642.       case NT_DEVICE:
  643. /*         
  644.          while (dev->lib_OpenCnt > 0)
  645.             CloseDevice( (struct IORequest *) dev );
  646.  
  647.          Forbid();
  648.             RemDevice( (struct Device *) dev );
  649.          Permit();         
  650. */
  651.          break;
  652.  
  653.       case NT_RESOURCE:
  654.          /*
  655.          More work is needed here!!
  656.          */
  657.          break;      
  658.       }
  659.       
  660.    (void) FlushClicked( 0 ); // Remove from system & update ListView.
  661.  
  662.    return;
  663. }
  664.  
  665. PRIVATE int RemoveClicked( int dummy )
  666. {
  667.    if (CurrentDLR != NULL)
  668.       {
  669.       if (CurrentDLR->lib_Node.ln_Type == NT_LIBRARY
  670.           || CurrentDLR->lib_Node.ln_Type == NT_DEVICE)
  671.          {
  672.          sprintf( ErrMsg, "Are you SURE you want to Remove 0x%08LX?\n"
  673.                           "The open count is %d", 
  674.                           CurrentDLR, CurrentDLR->lib_OpenCnt
  675.                 );
  676.  
  677.          if (SanityCheck( ErrMsg ) != FALSE)
  678.             {
  679.             RemoveTheDevice( CurrentDLR );
  680.  
  681.             if (InitializeDeviceList() <= 0)
  682.                {
  683.                // No Devices known to SysBase!!
  684.                UserInfo( "No Devices/Libraries/Resources found!",
  685.                          "OS ERROR??"
  686.                        );
  687.                }
  688.  
  689.             GT_RefreshWindow( DLRWnd, NULL );
  690.             }
  691.          }
  692.       else
  693.          UserInfo( "Removal of resources NOT implemented yet!",
  694.                    "User Information:"
  695.                  );
  696.       }
  697.    else
  698.       {
  699.       // No Devices selected by the user:
  700.       UserInfo( "Select a Device/Library/Resource first!", "USER ERROR:" );
  701.  
  702.       return( (int) TRUE );
  703.       }
  704.  
  705.    return( (int) TRUE );
  706. }
  707.  
  708. // -----------------------------------------------------------------
  709.  
  710. PRIVATE int PriorityClicked( int dummy )
  711. {
  712.    IMPORT int ChangePriorityHandler( char *name, int ObjType, 
  713.                                      int frompri
  714.                                    );
  715.  
  716.    char *name   = CurrentDLR->lib_Node.ln_Name;
  717.    int   pri    = CurrentDLR->lib_Node.ln_Pri;
  718.    int   type   = CurrentDLR->lib_Node.ln_Type;
  719.       
  720.    if (ChangePriorityHandler( name, type, pri ) < 0)
  721.       {
  722.       int ans = 0;
  723.       
  724.       ans = Handle_Problem( "Couldn't open Priority Requester!\n"
  725.                             "   (Low memory condition?)", 
  726.                             "System ERROR:", NULL
  727.                           );
  728.  
  729.       if (ans != 0) // User pressed the ABORT! button.
  730.          {
  731.          return( FALSE );
  732.          }
  733.       }
  734.  
  735.    return( (int) TRUE );
  736. }
  737.  
  738. // -----------------------------------------------------------------
  739.  
  740. PRIVATE int OpenDLRWindow( void )
  741. {
  742.    struct NewGadget  ng;
  743.    struct Gadget    *g;
  744.    UWORD             lc, tc;
  745.    UWORD             wleft = DLRLeft, wtop = DLRTop, ww, wh;
  746.  
  747.    ComputeFont( Scr, Font, &CFont, DLRWidth, DLRHeight );
  748.  
  749.    ww = ComputeX( CFont.FontX, DLRWidth );
  750.    wh = ComputeY( CFont.FontY, DLRHeight );
  751.  
  752.    if ((wleft + ww + CFont.OffX + Scr->WBorRight) > Scr->Width)
  753.       wleft = Scr->Width - ww;
  754.  
  755.    if ((wtop + wh + CFont.OffY + Scr->WBorBottom) > Scr->Height)
  756.       wtop = Scr->Height - wh;
  757.  
  758.    if ((DLRFont = OpenDiskFont( Font )) == NULL)
  759.       return( -5 );
  760.  
  761.    if ((g = CreateContext( &DLRGList )) == NULL)
  762.       return( -1 );
  763.  
  764.    for (lc = 0, tc = 0; lc < DLR_CNT; lc++)
  765.       {
  766.       CopyMem( (char *) &DLRNGad[lc], (char *) &ng, 
  767.                (long) sizeof( struct NewGadget )
  768.              );
  769.  
  770.       ng.ng_VisualInfo = VisualInfo;
  771.       ng.ng_TextAttr   = Font;
  772.  
  773.       ng.ng_LeftEdge   = CFont.OffX + ComputeX( CFont.FontX,
  774.                                                 ng.ng_LeftEdge
  775.                                               );
  776.  
  777.       ng.ng_TopEdge    = CFont.OffY + ComputeY( CFont.FontY,
  778.                                                 ng.ng_TopEdge
  779.                                               );
  780.  
  781.       ng.ng_Width      = ComputeX( CFont.FontX, ng.ng_Width );
  782.       ng.ng_Height     = ComputeY( CFont.FontY, ng.ng_Height );
  783.  
  784.       DLRGadgets[lc] = g = CreateGadgetA( (ULONG) DLRGTypes[lc], 
  785.                              g, 
  786.                              &ng, 
  787.                              (struct TagItem *) & DLRGTags[tc] );
  788.  
  789.       while (DLRGTags[tc] != NULL)
  790.          tc += 2;
  791.  
  792.       tc++;
  793.  
  794.       if (g == NULL)
  795.          return( -2 );
  796.       }
  797.  
  798.    if ((DLRWnd = OpenWindowTags( NULL,
  799.  
  800.                    WA_Left,        wleft,
  801.                    WA_Top,         wtop,
  802.                    WA_Width,       ww + CFont.OffX + Scr->WBorRight,
  803.                    WA_Height,      wh + CFont.OffY + Scr->WBorBottom,
  804.  
  805.                    WA_IDCMP,       LISTVIEWIDCMP | BUTTONIDCMP 
  806.                      | IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW,
  807.  
  808.                    WA_Flags,       WFLG_DRAGBAR | WFLG_DEPTHGADGET 
  809.                      | WFLG_CLOSEGADGET | WFLG_SMART_REFRESH 
  810.                      | WFLG_ACTIVATE | WFLG_RMBTRAP,
  811.                    
  812.                    WA_Gadgets,     DLRGList,
  813.                    WA_Title,       DLRWdt,
  814.                    WA_ScreenTitle, &ScrTitle[0],
  815.                    TAG_DONE )
  816.       ) == NULL)
  817.       return( -4 );
  818.  
  819.    GT_RefreshWindow( DLRWnd, NULL );
  820.  
  821.    return( 0 );
  822. }
  823.  
  824. PRIVATE int DLRVanillaKey( int whichkey )
  825. {
  826.    int rval = TRUE;
  827.    
  828.    switch (whichkey)
  829.       {
  830.       case 'u':
  831.       case 'U':
  832.          rval = UpdateClicked( 0 );
  833.          break;
  834.          
  835.       case 'c':
  836.       case 'C':
  837.       case 'q':
  838.       case 'Q':
  839.          rval = CancelClicked( 0 );
  840.          break;
  841.       }
  842.  
  843.    return( rval );
  844. }
  845.  
  846. PRIVATE int HandleDLRIDCMP( void )
  847. {
  848.    struct IntuiMessage  *m;
  849.    int                 (*func)( int code );
  850.    BOOL                  running = TRUE;
  851.  
  852.    while (running == TRUE)
  853.       {
  854.       if ((m = GT_GetIMsg( DLRWnd->UserPort )) == NULL)
  855.          {
  856.          (void) Wait( 1L << DLRWnd->UserPort->mp_SigBit );
  857.          continue;
  858.          }
  859.  
  860.       CopyMem( (char *) m, (char *) &DLRMsg, 
  861.                (long) sizeof( struct IntuiMessage )
  862.              );
  863.  
  864.       GT_ReplyIMsg( m );
  865.  
  866.       switch (DLRMsg.Class)
  867.          {
  868.          case IDCMP_REFRESHWINDOW:
  869.             GT_BeginRefresh( DLRWnd );
  870.             GT_EndRefresh( DLRWnd, TRUE );
  871.             break;
  872.  
  873.          case IDCMP_CLOSEWINDOW:
  874.             running = DLRCloseWindow();
  875.             break;
  876.  
  877.          case IDCMP_VANILLAKEY:
  878.             running = DLRVanillaKey( (int) DLRMsg.Code );
  879.             break;
  880.  
  881.          case IDCMP_GADGETUP:
  882.          case IDCMP_GADGETDOWN:
  883.             func = (void *) ((struct Gadget *) DLRMsg.IAddress)->UserData;
  884.             if (func != NULL)
  885.                running = func( (int) DLRMsg.Code );
  886.    
  887.             break;
  888.          }
  889.       }
  890.    
  891.    return( running );
  892. }
  893.  
  894. PUBLIC int HandleDeviceLV( void )
  895. {
  896.    int i = 0;
  897.  
  898.    // Open Libraries, Screen & Window:
  899.    if (SetupSystemList( &OpenDLRWindow ) < 0)
  900.       {
  901.       UserInfo( "Couldn't open a System ListViewer!", 
  902.                 "Allocation Problem:"
  903.               );
  904.  
  905.       return( -1 );
  906.       }
  907.  
  908.    // Disable buttons until user selects a Device from the ListView:
  909.  
  910.    GT_SetGadgetAttrs( DLRGadgets[ RemoveBt ], DLRWnd, NULL,
  911.                       GA_Disabled, TRUE, TAG_DONE 
  912.                     );
  913.  
  914.    GT_SetGadgetAttrs( DLRGadgets[ Priority ], DLRWnd, NULL,
  915.                       GA_Disabled, TRUE, TAG_DONE 
  916.                     );
  917.  
  918.    GT_SetGadgetAttrs( DLRGadgets[ Close ], DLRWnd, NULL,
  919.                       GA_Disabled, TRUE, TAG_DONE 
  920.                     );
  921.    
  922.    DLRNode.ln_Succ = (struct Node *) DLRList.mlh_Tail;
  923.    DLRNode.ln_Pred = (struct Node *) DLRList.mlh_Head;
  924.    DLRNode.ln_Type = 0;
  925.    DLRNode.ln_Pri  = MAXDEVS - 129;
  926.    DLRNode.ln_Name = tstr;
  927.  
  928.    DLRNodes[0]     = DLRNode;
  929.  
  930.    SetNotifyWindow( DLRWnd ); // For Handle_Problem().
  931.  
  932.    DisplayTitle( DLRWnd, "Initializing list..." );
  933.  
  934.    // DLRNodes[0] is already set up:
  935.  
  936.    for (i = 1; i <= MAXDEVS; i++)
  937.        {
  938.        DLRNodes[i].ln_Name = &NodeStrs[ i * NODELENGTH ];
  939.        DLRNodes[i].ln_Pri  = MAXDEVS - i - 129;
  940.        }     
  941.  
  942.    NewList( (struct List *) &DLRList );
  943.  
  944.    for (i = 0; i < MAXDEVS; i++)
  945.       Enqueue( (struct List *) &DLRList, &DLRNodes[i] );
  946.  
  947.    (void) InitializeDeviceList();
  948.  
  949.    GT_SetGadgetAttrs( DEVICELISTGADGET, DLRWnd, NULL,
  950.                       GTLV_Labels,       &DLRList,
  951.                       GTLV_Selected,     0, 
  952.                       GTLV_MaxPen,       255,
  953.                       GTLV_ItemHeight,   12,
  954.                       TAG_END
  955.                     );
  956.  
  957.    GT_RefreshWindow( DLRWnd, NULL );
  958.  
  959.    (void) HandleDLRIDCMP();
  960.  
  961.    // Close the Screen & Libraries:   
  962.    ShutdownSystemList();
  963.    return( 0 );
  964. }
  965.  
  966. #ifdef DEBUG
  967.  
  968. PUBLIC int main( void )
  969. {
  970.    return( HandleDeviceLV() );
  971. }
  972.  
  973. #endif
  974.  
  975. /* ----------------------- END of SysDevs.c file! ----------------- */
  976.